import pygame
import import_image
from constants import Constants
class Menu:
    def __init__(self, screen):
        self.screen = screen
        self.option = Constants.START_GAME
        self.index = 0
        self.options = []
        self.clock = pygame.time.Clock().tick(Constants.CLOCK)
        self.start = True

    def run_menu(self):
        while self.start:
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        self.option = Constants.EXIT_GAME
                        self.start = False
                    if event.key == pygame.K_RETURN:
                        self.option = self.index
                        self.start = False
                    if event.key == pygame.K_DOWN:
                        self.index = Constants.EXIT_GAME
                    if event.key == pygame.K_UP:
                        self.index = Constants.START_GAME
                elif event.type == pygame.QUIT:
                    self.option = Constants.EXIT_GAME
                    self.start = False
            
            self.update_menu(self.index)
            pygame.display.flip()
            self.clock
    
    def load_images_menu(self, file_name1 = "menu1.png", file_name2 = "menu2.png"):
        surface1 = pygame.image.load(import_image.filepath(file_name1))
        surface2 = pygame.image.load(import_image.filepath(file_name2))
        self.options.append(surface1)
        self.options.append(surface2)
        
    def update_menu(self, index):
        self.screen.blit(self.options[index], (0, 0))